package com.sunjee.system.controller;

import cn.hutool.core.lang.Dict;
import com.framework.common.api.CommonResult;
import com.framework.common.exception.ApiException;
import com.sunjee.dubbo.dto.SysUserDTO;
import com.sunjee.dubbo.service.system.SysUserApiService;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author lihanbo
 */
@Api(tags = "项目默认")
@Controller
@AllArgsConstructor
@Slf4j
public class IndexController {

    @Autowired
    private SysUserApiService sysUserApiService;

    @GlobalTransactional
    @ApiOperation("getUserInfo")
    @PostMapping("/getUserInfo")
    @ResponseBody
    public CommonResult<SysUserDTO> getUserInfo(@RequestBody Dict dict) {
        SysUserDTO userInfo = sysUserApiService.getUserInfo(dict.getLong("id"));
        if (userInfo == null) {
            throw new ApiException("抛出异常");
        }
        return CommonResult.success(userInfo);
    }
}
